package de.urlaub.client.gui;

import java.awt.BorderLayout;

import javax.naming.Context;
import javax.naming.NamingException;
import javax.swing.JPanel;
import javax.swing.JTable;

import de.urlaub.client.logic.VacationPanelUtil;
import de.urlaub.server.logic.DataUtilRemote;

public class SoonVacationPanel extends JPanel 
{
	private DataUtilRemote dataUtil;
	
	public SoonVacationPanel(DataUtilRemote dataUtil)
	{
		this.dataUtil = dataUtil;
		try
		{
			Context context = VacationPanelUtil.getInitialContext();
			this.dataUtil = (DataUtilRemote) context.lookup("DataUtil/remote");
		}
		catch (NamingException nEx)
		{
			nEx.printStackTrace();
		}
		
		this.setName("Bevorstehende Urlaube");
		this.setVisible(true);
	}
	
	@Override
	public String toString()
	{
		return this.getName();
	}
	
	public void buildPanel()
	{
		this.removeAll();
		this.setLayout(new BorderLayout());
		
		this.dataUtil.queryVacations(2);
		
		JTable vacationTable = new JTable(this.dataUtil.getVacationTableData(true),
										  this.dataUtil.getVacationColumnNames(true));
		this.add(vacationTable, BorderLayout.CENTER);
	}
}
